import java.util.*;

public class Collection_ {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();// 无序：根据哈希值有个顺序
        map.put("3","c");
        map.put("1","a");
        map.put("2","b");
        System.out.println(map);
        System.out.println("=================");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.print("key："+entry.getKey()+"\tvalue："+entry.getValue());
            System.out.println();
        }

    }

    public static void main3(String[] args) {
        Map<String,String> map = new HashMap<>();// 无序：根据哈希值有个顺序
        map.put("1","a");
        map.put("2","b");
        map.put("3","c");
        String ret = map.get("4");
        System.out.println(ret);// 没有的话，获取一个null
        // 也可以在后面设置一个默认值 getOrDefault()
        String ret2 = map.getOrDefault("4","小小胖三团");
        System.out.println(ret2);
    }

    public static void main2(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("hello");
        collection.add("main");
        Object[] objects = collection.toArray();// 转为一个数组
        System.out.println(Arrays.toString(objects));
    }

    public static void main1(String[] args) {
        // 泛型：指定集合放的数据类型
        // <>里只能放类类型，不能是简单的基本数据类型（放包装类）
        Collection<String> collection = new ArrayList<>();
        collection.add("hello");
        collection.add("main");
        collection.clear();

        System.out.println(collection);
    }
}
